package cn.swu.lyx.homework2

import android.content.Intent
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView


class userFragment : Fragment() {

    val userList= arrayListOf<User>()
    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment

        val view=inflater.inflate(R.layout.fragment_user_management, container, false)
//        initRecyclerView()
        return view
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        initUser()
        val recyclerView=view.findViewById<RecyclerView>(R.id.recyclerView)
        if (recyclerView != null) {
            recyclerView.layoutManager= LinearLayoutManager(managementSystem())
            recyclerView.adapter=UserAdapter(userList)
        }
    }

    private fun initUser(){
        repeat(20){
            userList.add(
                User().apply {
                    image=R.drawable.user
                    ID="易只羊"
                    name="千禧"
                    sex="男"
                    tel="13688888888"
                    type="管理员"
                }
            )
            userList.add(
                User().apply {
                    image=R.drawable.user
                    ID="易只猪"
                    name="千欢"
                    sex="女"
                    tel="13688888888"
                    type="管理员"
                }
            )
        }
    }


}